﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using MySql.Data.MySqlClient;

public partial class Modules_Modules_Register : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button_Reg_Click(object sender, EventArgs e)
    {
        string RegUsername = TextBox_RegUserName.Text.Trim();
        string RegProblem = TextBox_RegProblem.Text.Trim();
        string RegEmail = TextBox_RegEmail.Text.Trim();
        string RegAnswer = TextBox_Answer.Text.Trim();
        string RegPassWord = TextBox_RegPassWord.Text.Trim();
        string RegPassRepet = TextBox_RegRepPassWord.Text.Trim();
        string Regqq=TextBox_qq.Text.Trim();
        string RegTel=TextBox_TelPhone.Text.Trim();
        if (RegUsername != "" && RegProblem != "" && RegEmail != "" && RegAnswer != "" && RegPassWord != "" && RegPassRepet != ""&&Regqq!=""&&RegTel!="")
        {
            AsCheck AsUserCheck = new AsCheck();
            DataTable SelectTable = new DataTable();
            MysqlHelp SelectUser = new MysqlHelp();
            string SelectStr = "select * from user where username='" + RegUsername + "'";
            SelectTable=SelectUser.GetDatabysql(SelectStr);
            if(SelectTable.Rows.Count!=0)
            {
                Response.Write("<script>alert('用户名已注册！');history.go(-1);</script>");
            }
            else
            if (AsUserCheck.IsChineseAndNumb(RegUsername)==false)
            {
                Response.Write("<script>alert('用户名含有非法字符！');history.go(-1);</script>");
            }
            else
            {
                if (AsUserCheck.IsShortLen(RegPassWord,6)==true)
                {
                    Response.Write("<script>alert('密码太短，最小6位！');history.go(-1);</script>");
                }
                else
                {
                    if(AsUserCheck.IsEQual(RegPassWord,RegPassRepet)==false)
                    {
                        Response.Write("<script>alert('两次输入的密码不一样！');history.go(-1);</script>");
                    }
                    else
                    {
                        if(AsUserCheck.IsValidEmail(RegEmail)==false)
                        {
                            Response.Write("<script>alert('邮箱不合法！');history.go(-1);</script>");
                        }
                        else
                        {
                            if(AsUserCheck.IsAllNumber(RegTel)==false)
                            {
                                Response.Write("<script>alert('电话格式不合法！');history.go(-1);</script>");
                            }
                        else
                        {
                           MysqlHelp sqlreg=new MysqlHelp();
                            string sqlstr = "insert into user (username,password,email,qq,telphone,problem,answer,privilege) values('" + RegUsername + "','" + RegPassWord + "','" + RegEmail + "','" + Regqq + "','" + RegTel + "','" + RegProblem + "','" + RegAnswer + "',0)";
                            int back = sqlreg.Runsql(sqlstr);
                            if(back!=-1)
                            {
                                Response.Write("<script>alert('注册成功！');</script>");
                            }
                            else
                            {
                                Response.Write("<script>alert('无法完成注册！');history.go(-1);</script>");
                            }
                        }
                    }
                }
            }
        }
        }
        else
        {
            Response.Write("<script>alert('请填写完整的信息！');history.go(-1);</script>");
        }
    }
    protected void Button_Reset_Click(object sender, EventArgs e)
    {
        TextBox_RegUserName.Text = "";
        TextBox_RegRepPassWord.Text = "";
        TextBox_RegProblem.Text = "";
        TextBox_Answer.Text = "";
        TextBox_RegEmail.Text = "";
        TextBox_RegPassWord.Text = "";
        Page_Load(null,null);
    }
}
